#include "rightendmf.h"

RightEndMF::RightEndMF() : GraphicalMF("Right End", 3)
{
    /* Set the x and y values */
    m_points[0].setX(0);
    m_points[0].setY(0);

    m_points[1].setX(1);
    m_points[1].setY(1);

    m_points[2].setX(2);
    m_points[2].setY(1);
}

RightEndMF::RightEndMF(double newPoints[]) : GraphicalMF("Right End", 3)
{
    /* Set the x and y values in accordance to the array that was passed in */
    m_points[0].setX(newPoints[0]);
    m_points[0].setY(0);

    m_points[1].setX(newPoints[1]);
    m_points[1].setY(1);

    m_points[2].setX(newPoints[2]);
    m_points[2].setY(1);
}

RightEndMF::~RightEndMF()
{
}

void RightEndMF::paint(QPainter *painter, const double &xShift,
                       const double &xScale, const double &yShift,
                       const double &yScale) const
{
    /* Paint in the generic GraphicalMF style */
    this->GraphicalMF::paint(painter, xShift, xScale, yShift, yScale);

    /* Draw the name of the MF above it and near the center */
    painter->drawText(xShift + xScale * (m_points[2].x() + m_points[0].x())/2,
                      yShift + yScale - 4,
                      this->getName());
}

void RightEndMF::calculateCentroid()
{
    m_crisp_value=m_points[1].x();
}

void RightEndMF::calculateProbability(const double& crispInput)
{
    if( crispInput <= m_points[0].x())
    {
        m_fuzzy_value=0;
    }
    else if (m_points[1].x() <= crispInput)
    {
        m_fuzzy_value=1;
    }
    else if ( crispInput > m_points[0].x() && m_points[1].x() > crispInput )
    {
        m_fuzzy_value = (crispInput - m_points[0].x())/
                        (m_points[1].x() - m_points[0].x());
    }

}
